//====初始化swiftjs=开始===
function setupWebViewJavascriptBridge(callback) {
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'https://__bridge_loaded__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
}
var bridge;
setupWebViewJavascriptBridge(
     function(b){
        //注册供swift调用的方法
         b.registerHandler("fromSwift",fromSwift);
         bridge = b;
     }
);
//====初始化swiftjs=结束===
//====mui=开始===
mui.init({  swipeBack: false });
//====mui=开始===

//====以下与swift交互方法=开始===
//1. js调用swift方法
function callSwift1(){
    bridge.callHandler('fromJS');
}
//2. js调用swift方法并传递json参数
function callSwift2(){
    bridge.callHandler('fromJS',{"name":"有参数调用","id":1});
}
//3. js调用swift方法并传递json参数,并让swift回调处理结果
function callSwift3(){
    bridge.callHandler('fromJS',
                       {"name":"有参数还带回调","id":2},
                       function(data){
                            alert(data);
                       });
}
//4. js调用swift方法并传递json参数,并让swift回调处理结果,然后两次调用swift方法并传回结果
function callSwift4(){
    bridge.callHandler('fromJS',
                       {"name":"有参数还带回调第一次","id":2},
                       function(data){
                            alert("1.收到的参数,然后还要调用回去:\r\n"+data);
                            bridge.callHandler("fromJS",{name:"再次调用",data:data},function(resp){
                                          alert("2.两次调用返回来的结果:\r\n"+resp);
                                          });
                        });
}
//供swfit调用的方法
function fromSwift(data,callback){
    alert("我被swift调用了");
    if (data){
        alert("调用的数据为:\r\n"+data);
    }
    if (callback) {
        callback("swift调用js方法成功了,你满意了吧");
    }
}
